package com.v1.web.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.util.LabelValueBean;

import com.v1.lo.BaseLO;
import com.v1.lo.ItemLO;
import com.v1.lo.Statement;
import com.v1.model.Item;
import com.v1.model.Tag;
import com.v1.util.Toolkit;

public class DwrAction extends BaseDwrAction {
	protected final Log log = LogFactory.getLog(getClass());

	public Item good(Item model) throws Exception {
		Toolkit toolkit = Toolkit.getInstance();
		BaseLO lo = (BaseLO) toolkit.getBean("BaseLO");
		lo.update(model.getItemid(), Statement.Item_addScore);
		Item item = lo.queryForObject(model, Statement.Item_getItem);
		return item;
	}

	public Tag addTag(Tag model) throws Exception {
		if (StringUtils.isEmpty(model.getTag())) {
			return null;
		}
		if (null == model.getItemid() || model.getItemid() == 0) {
			return null;
		}
		model.setTag(model.getTag().trim());
		Toolkit toolkit = Toolkit.getInstance();
		BaseLO lo = (BaseLO) toolkit.getBean("BaseLO");
		Integer tagid = (Integer) lo.insert(model, Statement.Tag_addTag);
		Tag tag = new Tag();
		tag.setTagid(tagid);
		Tag newtag = lo.queryForObject(tag, Statement.Tag_getTags);
		return newtag;
	}

	public List<Tag> getTag(Tag model) throws Exception {
		Toolkit toolkit = Toolkit.getInstance();
		BaseLO lo = (BaseLO) toolkit.getBean("BaseLO");
		List<Tag> list = lo.queryForList(model, Statement.Tag_getTags);
		return list;
	}

	public List<LabelValueBean> llk_detail(Item model) throws Exception {
		Toolkit toolkit = Toolkit.getInstance();
		ItemLO lo = (ItemLO) toolkit.getBean("ItemLO");
		lo.update(model.getItemid(), Statement.Item_llk_addScore);
		List<LabelValueBean> details = lo.getItemDetails(model);
		return details;
	}
}
